<?php

class Session_gppHelper extends AppHelper{

	public function flash($key = 'flash', $attrs = array()) {
		$out = false;

		if (CakeSession::check('Message.' . $key)) {
			$flash = CakeSession::read('Message.' . $key);
			$message = $flash['message'];
			unset($flash['message']);

			$message=' 
			<a class="close" data-dismiss="alert" href="#">&times;</a>
            <h4 class="alert-heading"></h4>
            <p>'.$message.'</p>
	        <script type="text/javascript" charset="utf-8">
			  	$(function () {
				    $(".alert").alert();
				})
			  	$(function () {
					setTimeout(\'$(\\\'.alert.fade.in.alert-success\\\').alert(\\\'close\\\')\',5000);
				})
			</script>';

			if (!empty($attrs)) {
				$flash = array_merge($flash, $attrs);
			}

			if ($flash['element'] == 'default') {
				$class = 'alert alert-block';
				if (!empty($flash['params']['class'])) {
					$class = 'alert alert-block alert-'.$flash['params']['class'].' fade in';
				}
				$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>';
			} elseif ($flash['element'] == '' || $flash['element'] == null) {
				$out = $message;
			} else {
				$options = array();
				if (isset($flash['params']['plugin'])) {
					$options['plugin'] = $flash['params']['plugin'];
				}
				$tmpVars = $flash['params'];
				$tmpVars['message'] = $message;
				$out = $this->_View->element($flash['element'], $tmpVars, $options);
			}
			CakeSession::delete('Message.' . $key);
		}
		return $out;
	}

}